//
//  HomeSetionHeader.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/23.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class HomeSetionHeader: BaseTableHeaderFooterView {
    
    var bgView : UIView = {
        
        let temp = UIView(frame:CGRect(x: 0, y: 0, width: KScreenW, height: 36))
        
        temp.backgroundColor = UIColor.viewBgGrey()

        return temp
        
    }()
    
    var letfLine : UIView = {
        
        let temp = UIView()
        
        return temp
        
        
    }()
    
    var rightLine : UIView = {
        
        let temp = UIView()
        
        return temp
        
        
        
    }()
    
    var label : UILabel = {
        
        let temp = UILabel()
        
        
        return temp
        
        
        
    }()
    
    var title : String?{
    
    
        didSet{
        
        label.text = title
            
            if title == nil {
                
                bgView.isHidden = true
                
            } else {
                
                bgView.isHidden = false

            }
        
        
        }
    
    }
    
    

    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        bgView.addSubview(letfLine)
        bgView.addSubview(rightLine)
        bgView.addSubview(label)
        contentView.addSubview(bgView)
        
        let temp = UIColor.randomColor()
        letfLine.backgroundColor = temp
        rightLine.backgroundColor = temp
        label.textColor = temp
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        label.sizeToFit()
        
        label.center = CGPoint(x: KScreenW * 0.5, y: 36 * 0.5)
        
        letfLine.frame = CGRect(x: label.frame.origin.x - 54, y: 0, width: 44, height: 0.6)
        
        letfLine.center.y = label.center.y
        
        rightLine.frame = CGRect(x: label.frame.origin.x + label.frame.size.width + 10, y: 0, width: 44, height: 0.6)
        
        rightLine.center.y = label.center.y

    }
    

}

